package co.angluzha.commons.core.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * co.angluzha.commons.core.config文档说明
 *
 * @author Angluzha
 * @version 2022/11/23
 */
@Component
public class ApplicationUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public static <T>T getBean(Class<T> cls){
        return applicationContext.getBean(cls);
    }
    public static <T>T getBean(String cls){
        return (T) applicationContext.getBean(cls);
    }



    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        ApplicationUtils.applicationContext = applicationContext;
    }
}
